package com.huiyi.shopping_markt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huiyi.common.annotation.Log;
import com.huiyi.common.core.controller.BaseController;
import com.huiyi.common.core.domain.AjaxResult;
import com.huiyi.common.enums.BusinessType;
import com.huiyi.shopping_markt.domain.ShoppingMarkt;
import com.huiyi.shopping_markt.service.IShoppingMarktService;
import com.huiyi.common.utils.poi.ExcelUtil;
import com.huiyi.common.core.page.TableDataInfo;

/**
 * 商品Controller
 * 
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/shopping_markt/shopping_markt")
public class ShoppingMarktController extends BaseController
{
    @Autowired
    private IShoppingMarktService shoppingMarktService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShoppingMarkt shoppingMarkt)
    {
        startPage();
        List<ShoppingMarkt> list = shoppingMarktService.selectShoppingMarktList(shoppingMarkt);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShoppingMarkt shoppingMarkt)
    {
        List<ShoppingMarkt> list = shoppingMarktService.selectShoppingMarktList(shoppingMarkt);
        ExcelUtil<ShoppingMarkt> util = new ExcelUtil<ShoppingMarkt>(ShoppingMarkt.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shoppingMarktService.selectShoppingMarktById(id));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShoppingMarkt shoppingMarkt)
    {
        return toAjax(shoppingMarktService.insertShoppingMarkt(shoppingMarkt));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShoppingMarkt shoppingMarkt)
    {
        return toAjax(shoppingMarktService.updateShoppingMarkt(shoppingMarkt));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('shopping_markt:shopping_markt:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shoppingMarktService.deleteShoppingMarktByIds(ids));
    }
}
